{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c9a5a5cb",
   "metadata": {},
   "source": [
    "# list的热知识1.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "36b13ac0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n"
     ]
    }
   ],
   "source": [
    "#    -4,-3,-2,-1,0,1,2,3 数字排列\n",
    "\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a809e5e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jack\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7156d6b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "100e75c8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan']\n"
     ]
    }
   ],
   "source": [
    "# 从左往右取值时，右边的值取不到\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[1:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e434efaf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mike', 'Mary', 'Jan']\n"
     ]
    }
   ],
   "source": [
    "# 如果从0开始取值，0 可省略不写\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[:3])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4e26565f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan']\n"
     ]
    }
   ],
   "source": [
    "# 再从右往左取值时，右边的值取不到\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[-3:-1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d9ffd0e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan', 'Jack']\n"
     ]
    }
   ],
   "source": [
    "# 右侧不写任何值时能取到-1的值\n",
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "print(names[-3:])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8e55b0fe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0, 3, 6]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# 特殊情况 可以指定 slice 切片的步长 step\n",
    "num_list = list(range(10))\n",
    "print(num_list)\n",
    "print(num_list[0:7:3])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "402ab851",
   "metadata": {},
   "source": [
    "# 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "bc341eaf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MIKE\n",
      "123456\n",
      "21\n",
      "['MIKE', 123456, 21]\n"
     ]
    }
   ],
   "source": [
    "#构建列表形式[] 其中元素以”,“隔开\n",
    "# 列表是有顺序的一组值，顺序是从0位置开始的\n",
    "\n",
    "squares = [1,4,9,16,25]\n",
    "# names_str = \"MIKE,MARY,JAN,JACK\"\n",
    "user_data_list = [\"MIKE\",\"MARY\",\"JAN\",\"JACK\"]\n",
    "password_liat = [123456,345555,232423,439284]\n",
    "user_age = [21,23,25,28]\n",
    "# ...\n",
    "user_data = [[\"MIKE\",123456,21],[\"MARY\",345555,23]]\n",
    "\n",
    "# 应用：请取出每一个名字（如取第一个名字）\n",
    "# print(names_str[0])\n",
    "print(user_data_list[0])\n",
    "print(password_liat[0])\n",
    "print(user_age[0])\n",
    "print(user_data[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ac685300",
   "metadata": {},
   "source": [
    "# 用户输入补充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf2ac8b8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 补充用户信息：打印（print0）\n",
    "# input-> str 如果想让输入的数据类型变成int，需要强制转变数据类型\n",
    "# print(\"hello world\")\n",
    "\n",
    "name = input(\"name:\")\n",
    "age = int(input(\"age:\"))\n",
    "job = input(\"job:\")\n",
    "salary = input(\"salary:\")\n",
    "\n",
    "# 字符串拼接\n",
    "\n",
    "# info = '''-------- INFO '''+ name +''' ----------'''+'''\n",
    "# name:'''+ name +'''\n",
    "# age:'''+ age +'''\n",
    "# job:'''+ job +'''\n",
    "# salary:'''+ salary\n",
    "# print(info)\n",
    "\n",
    "# 占位符有顺序！请依次填入内容\n",
    "# 思考：如果有很多个位置呢？如果是一个HTML页面需要很多数据来占用位置\n",
    "#      对顺序要求太苛刻了，容易出错。\n",
    "# %s占位符，可以把”+“符号省略，比较直观的展示变量\n",
    "# %d占位符只能输入数字\n",
    "# input就为str\n",
    "\n",
    "\n",
    "# info_02 = '''--------INFO %S -------\n",
    "# name:%s\n",
    "# age:%s\n",
    "# job:%s\n",
    "# salary:%s\n",
    "# '''(name,name,age,job,salary)\n",
    "# print(info_02)\n",
    "\n",
    "# .format() 是一个字符串的格式化方法/函数 优化 占位符\n",
    "# {}.format()中占位符\n",
    "# 优势：1.不需要考虑参数出现的顺序和次数\n",
    "#      2.多个重复项只需要赋值一次（明确数据输入（如：变量age）和输出（如：打印的HTML_age））\n",
    "\n",
    "info_03 = '''-------INFO {HTML_name} ------\n",
    "name:{HTML_name}\n",
    "age:{HTML_age}\n",
    "job:{HTML_job}\n",
    "salary:{HTML_salary}\n",
    "'''.format(HTML_name=name,HTML_age=age,HTML_job=job,HTML_salary=salary)\n",
    "\n",
    "print(info_03)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7bcacc57",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
